package com.study;

import java.util.Scanner;

public class TestList {
    public static void main(String[] args) {
        LinearList<Integer> list=new LinkedList<>();
        int[] data={23,45,3,7,6,945};
        Scanner sc =new Scanner(System.in);
        char ch;
        do{
            System.out.println("------------------------------------");
            System.out.println("操作选项菜单");
            System.out.println("1.添加元素");
            System.out.println("2.插入元素");
            System.out.println("3.删除元素");
            System.out.println("4.定位元素");
            System.out.println("5.取表元素");
            System.out.println("6.显示线性表");
            System.out.println("0.退出");
            System.out.println("------------------------------------");
            System.out.println("请输入操作选项");
            ch =sc.next().charAt(0);
            switch(ch){
                case '1':
                    for(int i=0;i<data.length;i++){
                        list.add(data[i]);
                    }
                    System.out.println("添加操作成功");
                    break;
                case '2':
                    System.out.println("请输入要插入的位置");
                    int loc=sc.nextInt();
                    System.out.println("请输入要插入该位置的值");
                    int num=sc.nextInt();
                    list.add(loc,num);
                    System.out.println("插入成功！");
                    break;
                case '3':
                    System.out.println("请输入要删除元素的位置");
                    loc =sc.nextInt();
                    Integer remove = list.remove(loc);
                    System.out.println("删除的元素为： "+remove);
                    break;
                case '4':
                    System.out.println("请输入要查找的元素：");
                    num =sc.nextInt();
                    System.out.println("索引为"+list.indexOf(num));
                    break;
                case '5':
                    System.out.println("请输入要查找元素的位置");
                    loc =sc.nextInt();
                    System.out.println("该元素为"+list.get(loc));
                    break;
                case '6':
                    System.out.println("线性表的元素有： ");
                    for(int i=0;i<list.size();i++){
                        System.out.println(list.get(i));
                    }
                    System.out.println();
                    break;
            }
        }
        while(ch !='0');
            sc.close();

    }
}
